package day05;

import java.util.Arrays;
import java.util.Scanner;

public class StringDemo01 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("请输入一个字符串");
        String info = in.next();
        int length = info.length();//获取字符串长度
        System.out.println("你输入的字符串长度为:"+length);
        char c = info.charAt(5);//获取下标5对应的字符
        System.out.println("下标5对应的字符是:"+c);
        String s1 = info.substring(5);//获取下标5开始的所有字符
        System.out.println("s1="+s1);
        s1 = info.substring(0,5);//获取下标5之前的字符串
        System.out.println("s1="+s1);
        boolean f = info.equals("zhangsan");//判断用户输入的是不是张三
        System.out.println(f?"用户名正确":"用户名错误");
        f = info.equalsIgnoreCase("zhangsan");//忽略大小写比较是否相等
        System.out.println(f?"用户名正确":"用户名错误");
        s1 = info.toUpperCase();//将字符串转为大写
        System.out.println("s1全部大写:"+s1);
        s1 = info.toLowerCase();//将字符串转为小写
        System.out.println("s1全部小写:"+s1);
        //zhangsan:18:男:99
        String[] arr = info.split(":");
        System.out.println(Arrays.toString(arr));
        Person s = new Student();
        s.name = arr[0];
        s.sex = arr[2].equals("男")?true:false;
        ((Student)s).score = Double.parseDouble(arr[3]);
        System.out.println(s);
        String s2 = info.replace("男","女");
        System.out.println(s2);
        int index = info.indexOf("男");
        System.out.println("男第一次出现的位置是:"+index);
        info = "      li   si     ";
        System.out.println(info);
        String s3 = info.trim();//去除字符串两边的空白
        System.out.println(s3);
    }
}
